<template>
  <view class="page pageBg-color">

    <view class="head">
      <view class="left" v-if="dataInfo?.select">
        <uni-tag inverted text="置顶" type="error" />
      </view>
      <view class="right">
        <text>{{ dataInfo?.title }}</text>
      </view>
    </view>

    <view class="author">
      <view class="item">
        <text>{{ dataInfo?.author }}</text>
      </view>
      <view class="item">
        <text>{{ formatTimestamp(dataInfo?.publish_date) }}</text>
      </view>
    </view>

    <view class="content">
      <!-- <mp-html :content="dataInfo?.content" /> -->
      <rich-text :nodes="dataInfo?.content"></rich-text>
    </view>

    <view class="count">
      <text>阅读 {{ dataInfo?.view_count }} </text>
    </view>

  </view>
</template>


<script lang="ts" setup>
import { onLoad, onPullDownRefresh } from "@dcloudio/uni-app";
import { ref } from "vue";
import { API } from "@/services/api";
import { goHome, formatTimestamp } from "@/utils/utils";
// import mpHtml from 'mp-html/dist/uni-app/components/mp-html/mp-html';

const id = ref(""); // 公告资讯 ID
const dataInfo: any = ref(null); // 资讯信息

// 
onLoad((options: any) => {
  if (Object.keys(options).length === 0) {
    console.log('~~~页面加载失败：未接收到任何参数');
    goHome();
    return;
  }
  id.value = options.id;
  onRefresh();
});

// 
onPullDownRefresh(() => {
  onRefresh();
});

// 
const onRefresh = () => {
  getData();
};

// 
const getData = () => {
  API.wallNewsDetail(id.value)
    .then((res: any) => {
      dataInfo.value = res.data;
    })
    .catch((err: any) => {
      console.log(err);
    })
};
</script>


<style lang="scss" scoped>
@use "style.scss";
</style>